package com.example.myapplication;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.*;


public class RegisterActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.register);
        Log.v("tag_main", "onCreate RegisterActivity");
        Button zc = (Button) findViewById(R.id.register);
        zc.setOnClickListener(new View.OnClickListener() {


            public void onClick(View v) {

                //Toast.makeText(RegisterActivity.this,"按下注册按钮", Toast.LENGTH_SHORT).show();


                EditText usr = (EditText) findViewById(R.id.username);
                EditText psw1 = (EditText) findViewById(R.id.psw1);
                EditText psw2 = (EditText) findViewById(R.id.psw2);
                Register(usr.getText().toString().trim(), psw1.getText().toString().trim(), psw2.getText().toString().trim());
                Log.v("getRegister", "usr=" + usr.getText().toString() + " psw1=" + psw1.getText().toString() + " psw2=" + psw2.getText().toString());
            }
        });
        Button back = (Button) findViewById(R.id.r_login);
        back.setOnClickListener(new View.OnClickListener() {


            public void onClick(View v) {

                onBackPressed();
            }
        });
    }


    void Register(String usr, String psw, String psw_check) {
        if (usr.length() == 0 || psw.length() == 0 || psw_check.length() == 0) {

            Toast.makeText(RegisterActivity.this, "请输入完整信息!", Toast.LENGTH_SHORT).show();
            return;


        }else if (!psw.equals(psw_check)){

            Toast.makeText(RegisterActivity.this, "密码不一致!", Toast.LENGTH_SHORT).show();
            return;

        }else {

            Toast.makeText(RegisterActivity.this, "输入正确!", Toast.LENGTH_SHORT).show();
            return;


        }

    }

    @Override
    public void onBackPressed() {

        super.onBackPressed();
    }

}
